package com.cain.DontTapTheWhiteTile.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.cain.DontTapTheWhiteTile.R;
import com.cain.DontTapTheWhiteTile.tool.Constants;
import com.cain.DontTapTheWhiteTile.view.CustomDialog;

import java.util.Scanner;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /**
     * 游戏开始，具体游戏参数用view.tag判断
     * @param view
     */
    public void start(View view) {
        String tag = (String) view.getTag();
        Scanner scanner = new Scanner(tag);
        int mode = scanner.nextInt();
        int difficulty = scanner.nextInt();
        int count = scanner.nextInt();
        scanner.close();

        Intent intent = new Intent(MainActivity.this, GameControllerActivity.class);
        intent.putExtra("mode", mode);
        intent.putExtra("difficulty", difficulty);
        intent.putExtra("count", count);
        startActivity(intent);
    }

    @Override
    public void onBackPressed() {
        CustomDialog.Builder builder = new CustomDialog.Builder(this);
        builder.setTitle("亲~");
        builder.setMessage("确定要退出吗？");
        builder.setPositiveButton("结束", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                MainActivity.super.onBackPressed();
            }
        });
        builder.setNegativeButton("继续玩", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
    }
}
